<?php
/*
 * [JINYUN!] (C)2001-2099 Jinyunweb.com
 * This is NOT a freeware, use is subject to license terms
 *公告管理
*/
defined('BY_JYA') or exit('error');
$_RQ['op']=$_RQ['op']?$_RQ['op']:'list';
$merchid=$this->checklogin();
if($_RQ['op']=='list'){
	$return['list']=pdo_fetchall('SELECT mid,SUM(price),count(1) FROM '.tablename('jy_weishop_order').' WHERE ispay=1 and merchid= '.$merchid.' group by mid');
	foreach($return['list'] as $k=>&$v){
    	$member=pdo_get('core_members',array('id'=>$v['mid'],'uniacid'=>$_SESSION['uniacid']),array('id','nickname','mobile'));
        $member2=pdo_get('jy_weishop_member',array('merchid'=>$merchid,'mid'=>$v['mid'],'uniacid'=>$_SESSION['uniacid']),'level');
        $member3=pdo_get('jy_weishop_member_level',array('merchid'=>$merchid,'id'=>$member2['level']),'title');
        if(!$member['id']){
            unset($return['list'][$k]);
            continue;
        }
		if($member['nickname']){
			$v['nickname']=$member['nickname'];
		}else{
			$v['nickname']='散客用户'.$v['mid'].'(未授权)';
		}
		$v['mobile']=$member['mobile'];
		$v['rank']=$k+1;
		$v['total']=$v['count(1)'];
		$v['totalprice']=$v['SUM(price)'];
	}
	paixu($return['list'],'SUM(price)','desc');
	foreach($return['list'] as $k=>&$v){
		$v['rank']=$k+1;
	}
	$htmls=array(
		'type'=>'list',
		
		'list'=>array('data'=>'list','delall'=>false,'del_one'=>false,'edit'=>false,'list'=>array(
			array('name'=>'rank','title'=>'排行','type'=>'string'),
			array('name'=>'nickname','title'=>'会员昵称','type'=>'string'),
			array('name'=>'mobile','title'=>'手机号','type'=>'string'),			
			array('name'=>'totalprice','title'=>'消费金额','type'=>'string'),
			array('name'=>'total','title'=>'订单数','type'=>'string'),
			
		)),
	
	);

	$return['htmls']=$htmls;
	
	exi($return);
}
